import {
	request
} from '@/api/request/index.js'
import local_userinfo from '@/util/user/local-userinfo.js'
//用户缓存信息
let userSession = local_userinfo.getUserinfo();
export default {
	data(){
		return{
			orderid:'',
			needpay:0,
			payList:[]
		}
	},
	onLoad:function(options){
		let orderid = options.oid;
		this.orderid = orderid;
		this.getOrderinfo();
		// #ifdef MP-WEIXIN
		uni.hideShareMenu()
		// #endif
	},
	methods:{
		getOrderinfo(){
			let that =this;
			uni.showLoading({
				mask: true,
				title: '获取订单信息...'
			});
			request.get({
					data: {
						c: 'AddPaymentController',
						m: 'GetOrderInfo',
						rediskey: userSession.sessionid,
						orderid: that.orderid
					}
				})
				.then(res => {
					console.log(res)
					if (res.Status == "ok") {
						let result = res.Tag;
						that.needpay = result.pay.toFixed(2);
						let payment = result.payment.split(',');
						let paylist=[]
						payment.map((p)=>{
							paylist.push({
								icon:that.$resBaseurl+ '/m-images/happy/pay/'+(p=='微信支付'?'wxpay.png':'hdfk.png'),
								name:p
							})
						})
						
						that.payList = paylist
					} else {
						uni.showModal({
							title:res.Msg,
							showCancel:false
						})
					}
				})
				.catch(error => {
					console.error(error)
					
				});
		},
		gotoPay(paymentname){
			let that =this;
			uni.showLoading({
				mask: true,
				title: '正在请求支付...'
			});
			request.get({
					data: {
						c: 'AddPaymentController',
						m: 'Push',
						rediskey: userSession.sessionid,
						orderid: that.orderid,
						payment:paymentname
					}
				})
				.then(res => {
					console.log(res)
					if (res.Status == "ok") {
						let result=res.Tag;
						uni.redirectTo({
							url: result
						})
					} else {
						uni.showModal({
							title:res.Msg,
							showCancel:false
						})
					}
				})
				.catch(error => {
					console.error(error)
					
				});
		},
	}
}